<?php
class model_user extends base_model{
	private $result = array(
		'state' => 404,
		'message' => '',
	);
	
	public function __construct() {
		//默认不用登录
		$this->usercheck = false;
		parent::__construct();
	}
	/*
	 * 管理员用户修改密码保存
	 * @param string $uid 用户id
	 * @param string $pwd 加密后的密码
	 * @param string $keyt 密钥
	 * return int 受影响的行数
	 */
	public function mod_login_repass_save($uid,$pwd,$keyt){
        $sql = "UPDATE `@@admin_members` SET `password`='{$pwd}',`keyt`='{$keyt}' WHERE `uid`={$uid} LIMIT 1";
		return $this->db->query($sql, 0);
	}
	/*
	 * 查找指定用户名的数据行
	 * @param string $username 用户名
	 */
	public function mod_userinfo_forusername($username){
		$sql = "SELECT * FROM `@@admin_members` WHERE `username`='{$username}' LIMIT 1";
		$user = $this->db->query($sql,2);
		return $user;
	}
	/*
	* 登录成功记录到数据库
	* @param array $session 日志数组列表
	* uid => 用户ID,
	* username => 用户名
	* session_key => SESSION ID,
	* logintime => 登录时间,
	* accesstime => 活动时间,
	* loginip => 已转换成int的登录IP
	* client_type => 客户端类型
	* browser => 客户端浏览器类型,chrome,IE,android app,iOs app
	*/
	public function mod_loginSaveSession($session,$user){
		$session_id = $this->db->insert('@@admin_session', $session);
		if ($session_id) $user['sessionId'] = $session_id;
		$_SESSION[$this->user_session] = serialize($user);
		$uid = $user['uid'];
		$this->db->query("UPDATE `@@admin_session` SET `isonline`=0,`state`=1 WHERE `uid`={$uid} AND `id`<{$session_id}", 0);
	}
}